package com.googlecode.kipler.container.dl;

import com.googlecode.kipler.common.Copyable;
import com.googlecode.kipler.container.generic.MultivalueHashMap;
import com.googlecode.kipler.syntax.formula.Formula;


/**
 * 
 * @author İnanç Seylan
 * 
 */
public class DependencyManager implements Copyable<DependencyManager> {

	private MultivalueHashMap<Formula, WorldConstraintSystem> dependencies = new MultivalueHashMap<Formula, WorldConstraintSystem>();

	public void add(Formula f, WorldConstraintSystem wcs) {
		dependencies.put(f, wcs);
	}

	public void addAll(Formula f, DependencySet wcsSet) {
		for (WorldConstraintSystem wcs : wcsSet) {
			dependencies.put(f, wcs);
		}
	}

	public void move(Formula into, Formula from) {
		addAll(into, getDependencies(from));
	}

	public DependencySet getDependencies(Formula f) {
		return new DependencySet(dependencies.getValuesForKey(f));
	}

	public void remove(Formula f) {
		dependencies.remove(f);
	}

	public DependencyManager copy() {
		DependencyManager result = new DependencyManager();
		result.dependencies = dependencies.copy();
		return result;
	}

}
